﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">
        body {
            text-align: center;
        }
    </style>
    <link href="Resource/JavaScript/layui/css/layui.css" rel="stylesheet" />
    <script src="Resource/JavaScript/jquery-1.11.3/jquery.min.js"></script>
    <script src="Resource/JavaScript/layui/layui.all.js"></script>
</head>
<body>
    <form id="loginForm" class="layui-form" style=" width:350px; float:left; position:fixed; left:30%; top:30%;">
        <div class="layui-form-item">
            <i class="layui-icon layui-icon-friends" style="font-size: 30px; color: #1E9FFF;"></i>   <span style=" font-size:20px;"> Office Online</span>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"> 用户名</label>
            <div class="layui-input-block">
                <input type="text" id="account" name="account" required lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input" value="wangwc">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"> 密码框</label>
            <div class="layui-input-block">
                <input type="password" id="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" value="1">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo"> 登录</button>
                <button type="button" class="layui-btn layui-btn-primary" onclick=" regist();"> 注册</button>
            </div>
        </div>
    </form>
    <script>
        layui.use('form', function () {
            var form = layui.form;
            form.on('submit(formDemo)', function (data) {
                $.ajax({
                    url: "/weboffice/login",
                    type: "post",
                    async: false,
                    cache: false,
                    dataType: "json",
                    data: {
                        "user_id": data.field.account,
                        "user_pwd": data.field.password
                    },
                    success: function (d) {
                        console.log(d);
                        if (d && d.Code) {
                            if (d.Code == "1") {
                                layer.msg("登录成功！");
                                var url = "http://" + window.location.host + d.Data.url + "?token=" + d.Data.token+"&userId="+data.field.account;
                                window.location.href = url;
                                return false;
                            } else {
                                layer.msg(d.Message);
                                $("#password").val("");
                                return false;
                            }
                        }
                    },
                    error: function (err) {    //url无效，请求失败；有Exception异常，没有捕获时。
                        console.log(err);
                    }
                });
                return false;

            })
        })

        function regist() {
            var url ="http://"+ window.location.host + "/register.html";
            layer.open({
                title:"注册",
                area:['500px','400px'],
                type: 2,
                content: url //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            });
        }
    </script>
</body>
</html>
